FROM leoatchina/ubuntu20.04
RUN apt update -y && \
  apt install -y supervisor openssh-server nginx bioperl libdbi-perl && \
  apt install -y openjdk-8-jdk xvfb libswt-gtk-4-java && \
  apt install -y python3-pip python3-dev && \
  apt install -y libharfbuzz-dev libfribidi-dev libpoppler-cpp-dev libcurl4-openssl-dev libssl-dev libxml2-dev devscripts && \
  apt install -y x11-apps && \
  apt autoremove -y && apt clean -y && apt purge -y && rm -rf /tmp/* /var/tmp/* /root/.cpan/*

# miniconda3
RUN cd /tmp && \
  curl https://mirrors.bfsu.edu.cn/anaconda/miniconda/Miniconda3-latest-Linux-x86_64.sh -o miniconda3.sh && \
  bash miniconda3.sh -b -p /opt/miniconda3 && \
  /opt/miniconda3/bin/conda install -n base -c conda-forge mamba && \
  apt autoremove -y && apt clean -y && apt purge -y && rm -rf /tmp/* /var/tmp/* /root/.cpan/* && /opt/miniconda3/bin/conda clean -a -y

RUN /opt/miniconda3/bin/mamba install -y -n base -c conda-forge xeus-python libxml2 libxslt libssh2 krb5 bat ranger-fm && \
  /opt/miniconda3/bin/pip install --no-cache-dir pynvim neovim-remote flake8 pygments python-language-server && \
  apt autoremove -y && apt clean -y && apt purge -y && rm -rf /tmp/* /var/tmp/* /root/.cpan/* && /opt/miniconda3/bin/conda clean -a -y

# R
RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9 && \
  add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu focal-cran40/' && \
  apt update -y && \
  apt upgrade -y && \
  apt install -y r-base r-base-dev && \
  apt autoremove -y && apt clean -y && apt purge -y && rm -rf /tmp/* /var/tmp/* /root/.cpan/*

# R studio
RUN cd /tmp && \
  curl https://download2.rstudio.org/server/bionic/amd64/rstudio-server-2023.03.1-446-amd64.deb -o rstudio.deb && \
  gdebi -n rstudio.deb && \
  apt autoremove -y && apt clean -y && apt purge -y && rm -rf /tmp/* /var/tmp/* /root/.cpan/*

# RUN cd /opt && \
#   curl https://download.java.net/java/GA/jdk17.0.2/dfd4a8d0985749f896bed50d7138ee7f/8/GPL/openjdk-17.0.2_linux-x64_bin.tar.gz -o openjdk-17.tar.gz && \
#   tar xvf openjdk-*.tar.gz && rm openjdk-*.tar.gz

# RUN cd /opt && \
#   curl https://download.java.net/java/GA/jdk11/9/GPL/openjdk-11.0.2_linux-x64_bin.tar.gz -o openjdk-11.tar.gz  && \
#   tar xvf openjdk-*.tar.gz && rm openjdk-*.tar.gz
# ENV JAVA_HOME=/opt/jdk-11.0.2

# configuration

# java, use java java 8 defaultly
ENV JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
ENV PATH=$JAVA_HOME/bin:$PATH
RUN R CMD javareconf

# users ports and dirs and configs
RUN echo "export LC_ALL='C.UTF-8'" >> /etc/profile
ENV WKUSER=datasci
ENV LANG C.UTF-8
ENV COUNTRY=CN
ENV PROVINCE=ZJ
ENV CITY=HZ
ENV ORGANIZE=SELF
ENV WEB=leatchina.datasci
ENV IP=0.0.0.0
ENV CHOWN=1
EXPOSE 8787 22
# config file
RUN mkdir -p /etc/rstudio /opt/config /opt/rc
COPY .bashrc .inputrc .bash_profile .configrc /opt/rc/
COPY rserver.conf /etc/rstudio/
COPY supervisord.conf entrypoint.sh /opt/config/
ENTRYPOINT ["bash", "/opt/config/entrypoint.sh"]
